/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#ifndef BACKINTCONST_H
#define BACKINTCONST_H

#include <string>
#include <vector>
#include "common/JsonHelper.h"
#include "define/Types.h"

namespace backint {
const uint32_t SUCCESS = 0;
const uint32_t FAILED = 1;

const int CONSTANTS_0 = 0;
const int CONSTANTS_1 = 1;
const int CONSTANTS_2 = 2;
const int CONSTANTS_3 = 3;
const int CONSTANTS_4 = 4;
const int CONSTANTS_5 = 5;
const int CONSTANTS_6 = 6;
const int CONSTANTS_7 = 7;
const int CONSTANTS_8 = 8;
const int CONSTANTS_9 = 9;
const int FILE_NAME_MAX_LENGTH = 2048; // 根据文档每个文件长度最多为512，每个条目有两个文件信息，外加一些其他信息

struct StuFileData {
    std::string m_filePath;
    uint64_t m_dataLength = -1;
};

struct StuEBIDData {
    std::string m_backupID;
    std::string m_filePath;
    std::string m_destPath;
};

struct StuFileInfo {
    std::string m_backintVersion;
    std::string m_softwareVersion;
    std::string m_backupID;
    std::string m_fileName;
    std::string m_destName;
    std::vector<StuFileData> fileData;
    std::vector<StuEBIDData> m_eBIDData;
    std::string m_inputFileTitle;
};

struct StuParam {
    std::string m_userId;
    std::string m_funType;
    std::string m_parFile;
    std::string m_inputFile;
    std::string m_outFile;
    std::string m_dtBackupId;
    uint32_t m_numberOfObj;
    std::string m_backupType;
    std::string m_version;
    std::string m_versionDetail;
};

struct PlugParams {
    std::string m_pid;
    std::string m_jobId;
    std::string m_subJobId;
    std::string m_dbName;
    std::string m_dataPath;
    std::string m_cachePath;
    std::string m_metaPath;
};

struct ResultParams {
    std::string m_pid;
    std::string m_jobId;
    std::string m_subJobId;
    std::string m_eBid;
    std::string m_function;
    std::string m_funType;
    std::string m_code;
    std::string m_bobyErr;
    std::string m_message;
};
int ReadPipeInfo(const std::string &filePath, StuFileInfo &stFileInfo);

// 创建多级目录
int CreateDirs(const std::string& path);
// 将JSON写入结果文件
uint32_t WriteResultToFile(const Json::Value &jsonValue, const std::string &outFile);
// 解析插件提供的参数文件
uint32_t ParsePluginParams(const std::string &paramFile, PlugParams &plugParams);
// 获取输入文件地址
uint32_t GetInFilePath(int argc, char** argv, std::string &filePath);
uint32_t GetVersionFromInfile(const std::string &filePath, std::string &version);
uint32_t GetDbNameFromInfile(std::string &filePath, std::string &dBName);
uint32_t WriteOutFile(const std::vector<std::string> &result, const std::string &outFile);
int GetBackupInfo(std::string input, StuFileInfo& stuFileInfo);
// 从长挂载路径中找到实际数据库的目录
std::string GetLogStoragePath(const std::string &parentPath, const std::string &dbName);
std::string GetFileName(const std::string &filePath);
// 获取日志长挂载的路径
uint32_t GetLogParentPath(const std::string &filePath, std::string &parentPath);
std::string GetCataLogStorePath(const std::string &filePath, std::string &cachePath);
// 获取可执行文件位置
std::string GetExeCurrentPath();
std::string GetCatalogParentPath(const StuParam &inParam, std::string &m_dataPath);
}

#endif